#ifndef ROBOTSLIDERVIEW_H
#define ROBOTSLIDERVIEW_H

#include <QWidget>
#include <QDebug>
#include <QScrollArea>
#include <QVBoxLayout>
#include <QFormLayout>
#include <QLabel>

#include "robot.h"
#include "editslider.h"
#include "robotcommands.h"
#include "history.h"

/**
 * @brief Provides a view to the robot through sliders to manipulate the joints.
 *
 * Because the view is so simple, the view and controller are combined.
 *
*/
class RobotSliderView : public QWidget
{
    Q_OBJECT
public:
    explicit RobotSliderView(QWidget *parent = 0);

    virtual void loadModel(Robot* robot);

    //Sets the joints that are displayed
    void show(int jointID);
    void show(const QList<int>& jointIDs);
    void showAll();
    void hide(int jointID);
    void hide(const QList<int>& jointIDs);
    void hideAll();
    void disable(int jointID);
    void disable(const QList<int>& jointIDs);
    void disableAll();
    void enable(int jointID);
    void enable(const QList<int>& jointIDs);
    void enableAll();

    void enableUndo(bool enabled);

    QList< QPair <int, float> > values() const;

private:
    Robot* _model;
    QScrollArea* _scrollArea;
    //The command inserted into the history when
    //a joint slider is done manipulating the robot.
    //We don't want to insert every incremental change
    //when the user is dragging the sliders, but
    //only one single command that will undo the whole
    //edit
    RobotCommandGroup* _editCommand;
    bool _undoEnabled;

    void createSliders();

    //Bundles up every QLabel and EditSlider pair into a list
    QList< QPair<QLabel*,EditSlider*> > getSliderPairs(const QList<int>& jointIDs);

signals:

private slots:
    //Listens the robot for changes to the model, and updates the sliders
    //accordingly
    void onJointAngleChanged(int jointID, float newVal, float oldVal);
    //Listens to the sliders for changes, then updates the model
    void onSliderValueChanged(int newVal);
    //Listens to the slider for the editing to be finished
    void onSliderEditFinished(int newVal);
};

#endif // ROBOTSLIDERVIEW_H
